package leetcode.l0526;

/**
 * @author Retain
 * @date 2021/5/26 18:25
 */
public class Easy_二叉树的最大深度_104 {
    int depth =1;
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return dfs(root, depth);
    }

    private int dfs(TreeNode root,int level) {
        if (level > depth) {
            depth = level;
        }
        if (root.left != null) {
            dfs(root.left, level+1);
        }
        if (root.right != null) {
            dfs(root.right, level+1);
        }
        return depth;
    }
}
